package com.nightpiter.view.drawer.simple;

import java.util.Collection;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;

import com.nightpiter.model.MetroModel;
import com.nightpiter.model.objects.Station;
import com.nightpiter.model.objects.Transition;
import com.nightpiter.model.objects.Tunnel;
import com.nightpiter.view.drawer.MetroDrawer;

/**
 * Drawer test realization
 * 
 * just shows how it works.
 * 
 * @author Ilya Shurigyn (honorik@gmail.com)
 * @author Eldar Abusalimov (eldar.abusalimov@gmail.com)
 * 
 */
public class SimpleMetroDrawer extends MetroDrawer {

	private Paint sPaint = new Paint();
	private Paint lPaint = new Paint();
	private Paint cPaint = new Paint();
	private Paint dPaint = new Paint();

	private static final float STATION_RADIUS = 5;
	private int screenCenterX = 150;
	private int screenCenterY = 240;
	private static final int SCALE = 10;

	MetroModel model;

	public SimpleMetroDrawer(MetroModel model) {
		super(model);
	}

	public void drawMetro(Canvas canvas) {

		sPaint.setAntiAlias(true);
		sPaint.setColor(Color.WHITE);
		sPaint.setStrokeWidth(STATION_RADIUS);
		sPaint.setStrokeCap(Paint.Cap.ROUND);

		lPaint.setAntiAlias(true);
		lPaint.setColor(Color.WHITE);
		lPaint.setStrokeWidth(12);
		lPaint.setStrokeCap(Paint.Cap.ROUND);

		cPaint.setAntiAlias(true);
		cPaint.setColor(Color.LTGRAY);
		cPaint.setStrokeWidth(24);
		cPaint.setStrokeCap(Paint.Cap.ROUND);

		dPaint.setAntiAlias(true);
		dPaint.setColor(Color.WHITE);
		dPaint.setStrokeWidth(8);
		dPaint.setStrokeCap(Paint.Cap.ROUND);

		for (Station station : model.getStations()) {
			for (Tunnel tunnel : station.getTunnels()) {
				this.drawTunnel(tunnel, canvas, 0);
			}
		}
		for (Station station : model.getStations()) {
			this.drawStation(station, canvas);
		}

	}

	private void drawStation(Station station, Canvas canvas) {
		float realX = screenCenterX + station.getPosition().x * SCALE;
		float realY = screenCenterY + station.getPosition().y * SCALE;

		canvas.drawPoint(realX, realY, sPaint);
		canvas.drawText(station.getName(), realX + 10, realY + 10, cPaint);
	}

	private void drawTunnel(Tunnel tunnel, Canvas canvas, int correction) {
		float fromRealX = screenCenterX
				+ tunnel.getFromStation().getPosition().x * SCALE;
		float toRealX = screenCenterX + tunnel.getToStation().getPosition().x
				* SCALE;
		float fromRealY = screenCenterY
				+ tunnel.getFromStation().getPosition().y * SCALE;
		float toRealY = screenCenterY + tunnel.getToStation().getPosition().y
				* SCALE;

		lPaint.setColor(tunnel.getLine().getColor());

		canvas.drawLine(fromRealX, fromRealY, toRealX, toRealY, lPaint);
	}

	public void setMapCenter(int x, int y) {
		// TODO Auto-generated method stub

	}

	public void setScale(int x) {
		// TODO Auto-generated method stub

	}

	public void selectStation(Station station, Canvas canvas) {
		// TODO Auto-generated method stub

	}

	public void showWay(Collection<Transition> transitions, Canvas canvas) {
		// TODO Auto-generated method stub

	}

}
